package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.ef.constant.StatusType;
import com.ef.dao.MaterialDao;
import com.ef.domain.Material;
import com.ef.service.MaterialService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class MaterialServiceImpl extends BaseServiceImpl implements
		MaterialService {

	private MaterialDao materialDao;

	public void delete(Material entity) {
		entity.setStatus(StatusType.INVALID);
		materialDao.update(entity);

	}

	public PaginationSupport<Material> findByExample(
			CustomExample<Material> example, int startIndex, int pageSize) {

		return materialDao.findPageByExample(example, startIndex, pageSize);
	}

	public Material findById(Long id) {

		return materialDao.findById(id);
	}

	public void saveOrUpdate(Material entity) {

		materialDao.saveOrUpdate(entity);
	}

	public MaterialDao getMaterialDao() {
		return materialDao;
	}

	public void setMaterialDao(MaterialDao materialDao) {
		this.materialDao = materialDao;
	}

	public List<Material> findALLVaild() {
		DetachedCriteria criterion = DetachedCriteria.forClass(Material.class);
		criterion.add(Restrictions.eq("status", StatusType.VALID));
		return materialDao.findAllByCriteria(criterion);
	}
}
